<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with pixels[] - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/p3/feed.rss?Tag=pixels%5B%5D</link>
      <pubDate>Sun, 08 Aug 2021 19:58:10 +0000</pubDate>
         <description>Tagged with pixels[] - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedpixels%5B%5D/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Moving Pixels/Changing Color Over Time</title>
      <link>https://forum.processing.org/two/discussion/21816/moving-pixels-changing-color-over-time</link>
      <pubDate>Wed, 05 Apr 2017 02:24:44 +0000</pubDate>
      <dc:creator>thedurf18</dc:creator>
      <guid isPermaLink="false">21816@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm new to Processing and to programming, so forgive me if this is an annoyingly rudimentary question. I would like to cluster pixels in certain areas of the window and move the cluster, while colors are changing gradually. Trying to get an ambient-like effect. I know putting them in an array would be the most practical. What I have so far:</p>

<p>size(500,500);</p>

<p>loadPixels();
for(int x = 0; x &lt; width; x++){
  for(int y = 0; y &lt; height; y++){
    pixels[x+y*width] = color(0,y/2,x/2);
  }
}
updatePixels();</p>
]]></description>
   </item>
   <item>
      <title>how to make a pixel transparent?</title>
      <link>https://forum.processing.org/two/discussion/21653/how-to-make-a-pixel-transparent</link>
      <pubDate>Tue, 28 Mar 2017 09:43:12 +0000</pubDate>
      <dc:creator>Xeronimo74</dc:creator>
      <guid isPermaLink="false">21653@/two/discussions</guid>
      <description><![CDATA[<p>I seem to recall there was already a topic on this but I can't find it ... so what I want to do is loop through an array of pixels and make all the pixels above a certain brightness value transparent. How would I do this? Thanks!</p>
]]></description>
   </item>
   <item>
      <title>NullPointer Exception Issue</title>
      <link>https://forum.processing.org/two/discussion/21566/nullpointer-exception-issue</link>
      <pubDate>Thu, 23 Mar 2017 23:09:27 +0000</pubDate>
      <dc:creator>AndresAlejandro</dc:creator>
      <guid isPermaLink="false">21566@/two/discussions</guid>
      <description><![CDATA[<p>I have a code that I need running for several hours. After several minutes it stops responding altogether (and I have to force quit the application) and gives me the error "NullPointer Exception" and highlights line 106. I have not been able to solve this, it may be because it runs out of pixels to grab? I am not sure. Another issue I am having is that it is using both my USB camera and my built-in mac camera. How do I get it to only use the USB camera? 
    final int kTotalGlitches=10;
    int currGlitch=0;
    PImage img;
    ArrayList glitches;</p>

<pre><code>final int kGlitchState=0;
final int kCamState=1;

int state=kCamState;


// ---------------------------------

final int kGlitchTimeLapse=7000;  // 2 secs
final int kCamTimeLapse=5000;    //8 secs
int triggerTime;

// ---------------------------------


import processing.video.*; 
Capture cam; 
Capture video;



void setup() { 
  size(1024, 768); 
  imageMode(CENTER);

  glitches = new ArrayList &lt;GlitchClass&gt;();
  for (int i=0; i&lt;kTotalGlitches; i++)
    glitches.add(new GlitchClass());

  cam = new Capture(this);
  cam.start();
  triggerTime=millis()+kCamTimeLapse;
  img = cam;
  video = new Capture(this, width, height);
  video.start();
} 

void draw() { 

  if (millis()&gt;=triggerTime) {

    if (state==kCamState) {
      state=kGlitchState;
      triggerTime+=kGlitchTimeLapse;
      currGlitch=int(random(kTotalGlitches));  //Select new glitch
    } else {
      state=kCamState;
      triggerTime+=kCamTimeLapse;
    }
  }

  if (state==kCamState)
    image(cam, width/2, height/2);
  else {
    background(0);
    glitches.get(currGlitch).display();
  }
} 


void captureEvent(Capture camera) {
  camera.read();

  img = createImage(width, height, RGB);
  video.loadPixels();
  arrayCopy(video.pixels, img.pixels);
}


//A glitch is just two ellipses overlapping on top of each other with different
//colors and one being rotated by 90 degrees.
class GlitchClass {

  void display() {

    loadPixels();

    int randPos = 0;
    if (frameCount  % 100 == 0)
      randPos = (int)random(0, video.height -4);

    int randPosY = 0;

    // if (frameCount  % 100 == 0)
    randPosY = (int)random(20, 50);

    // Begin a loop for displaying pixel rows of 4 pixels height
    for (int y = 0; y &lt; video.height -57; y++) {
      if (img != null) {
        img.loadPixels();

        // Put 4 rows of pixels on the screen
        if (frameCount % 50 == 0)
          randPosY = (int)random(20, 50);
        for (int x = 0; x &lt; video.width; x++) {
          if (frameCount % 100 == 0)
            randPosY = (int)random(20, 50);
          if (y &lt; video.height -4) {
            pixels[x + (y + 0 + randPosY)* width] = img.pixels[  (y + 0 )* video.width + randPos + x];
            pixels[x + (y + 1 + randPosY) * width] = img.pixels[ (y + 1) * video.width + randPos + 1 + x];
            pixels[x + (y + 2 + randPosY) * width] = img.pixels[ (y + 2) * video.width + randPos + 2 + x];
            pixels[x + (y + 3 + randPosY) * width] = img.pixels[ (y + 3) * video.width + randPos + 3 + x];

            pixels[x + (y + 4 + randPosY)* width] = img.pixels[  (y + 4 )* video.width + randPos + 4 + x];
            pixels[x + (y + 5 + randPosY) * width] = img.pixels[ (y + 5) * video.width + randPos + 5 + x];
            pixels[x + (y + 6 + randPosY) * width] = img.pixels[ (y + 6) * video.width + randPos + 6 + x];
            pixels[x + (y + 7 + randPosY) * width] = img.pixels[ (y + 7) * video.width + randPos + 7 + x];
          }
        }
      } else {
        break;
      }
    }

    updatePixels();
  }
}
</code></pre>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Blur logic but i don't think its working );</title>
      <link>https://forum.processing.org/two/discussion/20838/blur-logic-but-i-don-t-think-its-working</link>
      <pubDate>Fri, 17 Feb 2017 03:33:06 +0000</pubDate>
      <dc:creator>Anupam</dc:creator>
      <guid isPermaLink="false">20838@/two/discussions</guid>
      <description><![CDATA[<pre><code>            import processing.video.*;

            Capture video;
            PImage frog;
            public static final int[][] mask = {{1, 1, 1},
                                                   {1, 1, 1},
                                                   {1, 1, 1} };
            void setup()
            {
            size(640,480);
            video = new Capture(this,640,480);
            video.start();
            frog = loadImage("frog.jpg");

            }

            void captureEvent(Capture video){

              video.read();
            }


            void draw()
            {

              loadPixels();
              video.loadPixels();
              frog.loadPixels();
              for(int x=1;x+1&lt;video.width;x++)
              {
               for(int y=1;y+1&lt;video.height;y++)
               {
                 int loc  =  x+y*video.width;



                 color value  = applyBlur(video,x,y,mask);

                 pixels[loc] = value;


               }
              }
              updatePixels();
              }


              color applyBlur(Capture video,int x,int y,int[][] mask)
              {
                int red=0,green=0,blue=0;
                for(int j=-1;j&lt;=1;j++)
                {
                 for(int k=-1;k&lt;=1;k++)
                 {

                    red  += mask[1+j][1+k]*(red(video.get(x+k,y+j))); 
                    green +=mask[1+j][1+k]*(green(video.get(x+k,y+j)));
                    blue  += mask[1+j][1+k]*(blue(video.get(x+k,y+j)));
                 } 
                }
                   red = red/findSum(mask);
                   green = green/findSum(mask);
                   blue = blue/findSum(mask);

                   color value  = color(red,green,blue);
                   return value;

              }

              int  findSum(int[][] mask)
              {
                int sum=0;
                for(int y=0;y&lt;mask.length;y++)
                {
                   for(int x=0;x&lt;mask[y].length;x++)
                   {
                     sum += mask[y][x];
                   }
                }
                  return sum;

              }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Copy PGraphics by value</title>
      <link>https://forum.processing.org/two/discussion/20716/copy-pgraphics-by-value</link>
      <pubDate>Wed, 08 Feb 2017 14:38:49 +0000</pubDate>
      <dc:creator>cameyo</dc:creator>
      <guid isPermaLink="false">20716@/two/discussions</guid>
      <description><![CDATA[<p>Which is the best(fast) way  to copy two PGraphics (P1 over P2) by value ?<br />
P2 = P1 seems to copy by reference :(<br />
Thanks.<br />
cameyo</p>
]]></description>
   </item>
   <item>
      <title>Flickering of graphics drawn over video</title>
      <link>https://forum.processing.org/two/discussion/20700/flickering-of-graphics-drawn-over-video</link>
      <pubDate>Tue, 07 Feb 2017 15:53:34 +0000</pubDate>
      <dc:creator>cattaneopaul</dc:creator>
      <guid isPermaLink="false">20700@/two/discussions</guid>
      <description><![CDATA[<p>I'm having trouble with some code that I've patched together. I've managed to get this to mostly work, but when it runs the toplayer graphics over the video flicker, I think while the video updates. Is there a way to keep this from happening?</p>

<p>code below:</p>

<pre><code>import ipcapture.*;

IPCapture cam1;

// Circular buffer
PImage[] cam1_buffer; 

// These determine the size of the circular buffer and help iterate while writing and reading through them
int nFrames = 1;
int iWrite = 0, iRead = 1;

// Track color var
color trackColor;

//top layer drawing thing
PGraphics topLayer;

void setup() {

  size(704, 480);

  cam1 = new IPCapture(this, "http://" + "155.41.145.37/mjpg/video.mjpg", "", "");
  cam1.start();
  // If the camera resolution isn't explicitely defined the PImage.get() method will give strange results
  cam1.pixelWidth = 704;
  cam1.pixelHeight = 480;

  cam1_buffer = new PImage[nFrames];

  //Track color vars
  colorMode(RGB,255,255,255,100);
  trackColor = color(255,0,64);
  noFill();
  smooth();
  strokeWeight(4.0);
  stroke(0);

  //create a top layer for circles
  topLayer = createGraphics(width, height, g.getClass().getName());

}

void draw() {
  if (cam1.isAvailable()) {
    cam1.read();
    cam1_buffer[iWrite] = cam1.get();
  if(cam1_buffer[0] != null){
  // The original camera image is displayed correctly at 480x300 in the upper left corner          
  image(cam1,0,0);
  }
}

  //Track colors below
  loadPixels();


  //Color tracking vars
  float closestDiff = 500.0f;
  int closestX = 0;
  int closestY = 0;

  //Loop through every pixel
  for (int x = 0; x &lt; cam1.pixelWidth; x++){
    for (int y = 0; y &lt; cam1.pixelHeight; y++){
      int loc = x + y*cam1.pixelWidth;

      //what is current color
      color currentColor = cam1.pixels[loc];
      float r1 = red(currentColor);
      float g1 = green(currentColor);
      float b1 = blue(currentColor);
      float r2 = red(trackColor);
      float g2 = green(trackColor);
      float b2 = blue(trackColor);

      //Using euclidean distance to compare colors
      float d = dist(r1,g1,b1,r2,g2,b2);

      //If current color is more similar to tracked color than
      //closest color, save current location and current difference
      if (d &lt; closestDiff) {
        closestDiff = d;
        closestX = x;
        closestY = y;
      }
    }
  }

  //create a threshold
  //then create a circle at the tracked color

  if (closestDiff &lt; 100) {
    topLayer.beginDraw();
    topLayer.noFill();
    topLayer.strokeWeight(4.0);
    topLayer.stroke(trackColor);
    topLayer.ellipse(closestX, closestY, 50, 50);
    topLayer.endDraw();
    image(topLayer, 0, 0);

  } 
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>I need some help with image filters</title>
      <link>https://forum.processing.org/two/discussion/20650/i-need-some-help-with-image-filters</link>
      <pubDate>Sun, 05 Feb 2017 05:25:31 +0000</pubDate>
      <dc:creator>mysteriousLynx</dc:creator>
      <guid isPermaLink="false">20650@/two/discussions</guid>
      <description><![CDATA[<p>I don't understand what is wrong here, I am trying to use a matrix to apply some basic filters to images but I would like to modify the <code>PImage</code>directly instead of the pixels on the canvas itself by using <code>image.pixels[]</code> instead of just <code>pixels[]</code>, however, I do not really know if I am right about that anyways.</p>

<p>Here is Image_Filters</p>

<pre><code>PImage img; //&lt;&gt;// //&lt;&gt;// //&lt;&gt;// //&lt;&gt;// //&lt;&gt;//

void setup()
{
  size(600, 600);
  img = loadImage("2.jpg");
  surface.setSize(img.width, img.height);
  noLoop();
}

void draw()
{
  test(img);
  image(img, 0, 0);
}
</code></pre>

<p>and here is testDraw</p>

<pre><code>void test(PImage image)
{
  PImage temp = image;

  float kernel[][] = { {-1, -1, -1}, //Outlines
    {-1, 8, -1}, 
    {-1, -1, -1} };

  //float kernel[][] = { {0.0625, 0.125, 0.0625}, //Blur
  //  {0.125, 0.25, 0.125}, 
  //  {0.0625, 0.125, 0.0625} };

  temp.loadPixels();
  for (int x = 0; x &lt; image.width; x++)
  {
    for (int y = 0; y &lt; image.height; y++)
    {
      color newColor = applyFilter(x, y, kernel, temp);
      img.pixels[x + y * image.width] = newColor;
    }
  }
  img.updatePixels();
}

color applyFilter(int x, int y, float matrix[][], PImage image)
{
  float rTotal = 0;
  float gTotal = 0;
  float bTotal = 0;

  for (int i = 0; i &lt; 3; i++)
  {
    for (int j = 0; j &lt; 3; j++)
    {
      int location = constrain((x + i - 1) + (y + j - 1) * image.width, 
        0, image.pixels.length - 1);
      rTotal += (image.pixels[location] &gt;&gt; 16 &amp; 0xFF) * matrix[i][j];
      gTotal += (image.pixels[location] &gt;&gt; 8 &amp; 0xFF) * matrix[i][j];
      bTotal += (image.pixels[location] &amp; 0xFF) * matrix[i][j];
    }
  }
  rTotal = constrain(rTotal, 0, 255);
  gTotal = constrain(gTotal, 0, 255);
  bTotal = constrain(bTotal, 0, 255);
  return color(rTotal, gTotal, bTotal);
}
</code></pre>

<p>Okay, this is the problem...</p>

<p>Original:<img src="https://forum.processing.org/two/uploads/imageupload/872/Y34VYN1FLQB4.jpg" alt="2" title="2" /></p>

<p>Filter Applied:</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/987/2YAR5UHYB3C4.png" alt="something9000" title="something9000" /></p>

<p>Also, can someone explain what <code>//&lt;&gt;//</code> at the top of my main file is for? Processing did that by itself.</p>

<p>If I forgot to explain something please just ask.</p>

<p>Thank you very much for your help.</p>
]]></description>
   </item>
   <item>
      <title>Bit phase Slicing</title>
      <link>https://forum.processing.org/two/discussion/20448/bit-phase-slicing</link>
      <pubDate>Tue, 24 Jan 2017 15:16:07 +0000</pubDate>
      <dc:creator>Anupam</dc:creator>
      <guid isPermaLink="false">20448@/two/discussions</guid>
      <description><![CDATA[<pre><code>        PImage img;
        int[][] msb;
        int[][] lsb; 

        void setup() {
          size(300, 500); // same width, twice the height
          img = loadImage("women.gif");
          println(img.width, img.height);
          msb = new int[img.width][img.height];
          lsb = new int[img.width][img.height];
          noLoop();
        }

        void draw() {
          image(img, 0, 0);
          loadPixels();
          int x=0,y=0;
          img.loadPixels();
          for (int i = 0 ; i &lt; img.width  ; i++) {
            for(int j=0;j&lt;img.height;j++){

              int loc  =  i+j*img.width;
              int Pixels = img.pixels[loc] &amp; 0xff;
              msb[i][j] = (Pixels &gt;&gt; 23) &amp;0x1 ;
              lsb[i][j] = Pixels &amp; 0x1;

              pixels[loc+(img.width * img.height)] = 0xff000000|msb[i][j] &lt;&lt; 16 | msb[i][j] &lt;&lt; 8|msb[i][j] &amp; 0xff; 


            }
            }
          // debug

           for (int i = 0 ; i &lt; img.width  ; i++) {
            for(int j=0;j&lt;img.height;j++){
            print(msb[i][j]);
            }
        println("\n");  
        }

          updatePixels();
        }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Motion Detection</title>
      <link>https://forum.processing.org/two/discussion/16860/motion-detection</link>
      <pubDate>Sat, 28 May 2016 10:35:49 +0000</pubDate>
      <dc:creator>Luke12345</dc:creator>
      <guid isPermaLink="false">16860@/two/discussions</guid>
      <description><![CDATA[<p>What's wrong with my code. When I run the code, it pops out a grey windows nothing inside there. The camera should be activated and detect motion in the screen</p>

<pre><code>import processing.video.*; 
int numPixels;
int[] previousFrame;
Capture video;

void setup(){
  size (640, 480);
  video = new Capture (this, width, height);
  numPixels = video.width * video.height;
  previousFrame = new int[numPixels];
  video.start();

}

void draw() {
  if (video.available()){
    video.read();
    video.loadPixels();
    int movementSum=0;
    loadPixels();

    for (int i = 0; i &lt; numPixels; i++){
      color currColor = video.pixels[i];
      color prevColor = previousFrame[i];

      int currR = (currColor &gt;&gt; 16) &amp; 0xFF;
      int currG = (currColor &gt;&gt; 8) &amp; 0xFF;
      int currB = currColor &amp; 0xFF;

      int prevR = (currColor &gt;&gt; 16) &amp; 0xFF;
      int prevG = (currColor &gt;&gt; 8) &amp; 0xFF;
      int prevB = currColor &amp; 0xFF;

      int diffR = abs(currR - prevR);
      int diffG = abs(currG - prevG);
      int diffB = abs(currB - prevB);

      movementSum += diffR + diffG + diffB;
      pixels[i] = color(diffR,diffG,diffB);
      previousFrame[i] = currColor;
    }

   if (movementSum &gt; 0){
     updatePixels();
     println(movementSum);
   }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Shifting/re-shuffling pixels of an image</title>
      <link>https://forum.processing.org/two/discussion/19093/shifting-re-shuffling-pixels-of-an-image</link>
      <pubDate>Thu, 17 Nov 2016 15:01:53 +0000</pubDate>
      <dc:creator>Gene_Webber</dc:creator>
      <guid isPermaLink="false">19093@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I am new to programming in general. I've just watched Daniel Shiffman's video on pixel arrays, there he changes the [r g b a] values of a pixel and then applies that change to all of the pixels in an image using a nested for loop (code below). So I'm wondering if I could use a similar logic to actually move a whole pixel to a random coordinate in the image - and then apply that to the whole image so that all of the pixels shift into a random order? Many thanks for any advice given</p>

<p>function preload() {
  img1 = loadImage("Assets/randimage2.png");
}</p>

<p>function setup() {
  createCanvas(img1.width, img1.height);</p>

<p>}</p>

<p>function draw() {
  image(img1);</p>

<p>loadPixels();</p>

<p>for (var y = 0; y &lt; height; y++) {
    for(var x = 0; x &lt; width; x++) {
      var index = (x + y * width)*4;
      pixels[index+0] *2;
      pixels[index+1] = 200;
      pixels[index+2] = 255;
      pixels[index+3] = 105;
    }
  }</p>

<p>updatePixels();
}</p>
]]></description>
   </item>
   <item>
      <title>How to get the color value for a pixel in canvas</title>
      <link>https://forum.processing.org/two/discussion/19046/how-to-get-the-color-value-for-a-pixel-in-canvas</link>
      <pubDate>Tue, 15 Nov 2016 07:17:34 +0000</pubDate>
      <dc:creator>Gmacro</dc:creator>
      <guid isPermaLink="false">19046@/two/discussions</guid>
      <description><![CDATA[<p>I'm try to get a pixels[] type value for a pixel in the canvas, but all the methods I've found seem to deal exclusively with images as far as I can tell. Is there a way to use loadPixels() and subsequently pixels[] on the canvas or is it necessary to turn the canvas into an image somehow in order to sample it?</p>
]]></description>
   </item>
   <item>
      <title>Get current canvas?</title>
      <link>https://forum.processing.org/two/discussion/19029/get-current-canvas</link>
      <pubDate>Mon, 14 Nov 2016 10:33:21 +0000</pubDate>
      <dc:creator>Aldun</dc:creator>
      <guid isPermaLink="false">19029@/two/discussions</guid>
      <description><![CDATA[<p>Hey,</p>

<p>I'm trying to get the output of my canvas to perform blob detection on. How could I do this? I currently get the output of my cam, but I want to replace this with the output that is shown on the canvas (as I have performed some pixel editting on it)</p>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>pixels() conceptual questions :|</title>
      <link>https://forum.processing.org/two/discussion/18220/pixels-conceptual-questions</link>
      <pubDate>Tue, 20 Sep 2016 11:29:04 +0000</pubDate>
      <dc:creator>ayruos</dc:creator>
      <guid isPermaLink="false">18220@/two/discussions</guid>
      <description><![CDATA[<p>I had some quick conceptual questions regarding pixels() which I'm having trouble grasping.</p>

<p>So basically I want to get the r, g and b values of my current mouse position. Now, I want this sketch to work irrespective of the window size (which happens to be 600x900 at the moment) - so I'm resizing using the resize function. Do i need to use loc = x + y*width differently now? And a little confused how to translate that to my current mouse position as well. Haven't really used PImage till now in Processing even though I've been using P5 for generative art for a while now. Some nice links would also be welcome, while the snippets in the reference give some ideas it's not really conceptually enlightening for bigger projects.</p>
]]></description>
   </item>
   <item>
      <title>Understanding code from NatureOfCode book, nested loops in noise()</title>
      <link>https://forum.processing.org/two/discussion/17219/understanding-code-from-natureofcode-book-nested-loops-in-noise</link>
      <pubDate>Sun, 19 Jun 2016 19:04:06 +0000</pubDate>
      <dc:creator>marciokoko</dc:creator>
      <guid isPermaLink="false">17219@/two/discussions</guid>
      <description><![CDATA[<p>Im looking through the introduction of the book: <a href="http://natureofcode.com/book/introduction/" target="_blank" rel="nofollow">http://natureofcode.com/book/introduction/</a></p>

<p>and we are looking at 2D Noise and the author presents this code:</p>

<pre><code>loadPixels();
for (int x = 0; x &lt; width; x++) {
  for (int y = 0; y &lt; height; y++) {
    float bright = random(255);
    pixels[x+y*width] = color(bright);
  }
}
updatePixels();
</code></pre>

<p>The author then goes on to show how we can use noise() instead of random.  But Im confused as to the code snippet and how it creates noise.  So this is what I do understand:</p>

<ol>
<li>it loads all pixels?</li>
<li>then the first for loop checks if x is &lt; width and moves over by 1.  So if the pixel was (5,5), x=6.</li>
<li>then the next loop checks if y is &lt; height and moves over by 1.  So y=6, thus (6,6)</li>
<li>it creates a random brightness value</li>
<li>finally sets that brightness to an array called pixel at the element [5+5*width] ?</li>
</ol>
]]></description>
   </item>
   <item>
      <title>How to make 2D noise in p5.js</title>
      <link>https://forum.processing.org/two/discussion/15820/how-to-make-2d-noise-in-p5-js</link>
      <pubDate>Sun, 03 Apr 2016 07:36:43 +0000</pubDate>
      <dc:creator>steven</dc:creator>
      <guid isPermaLink="false">15820@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I am trying to make a 2D noise texture in P5.JS.</p>

<p>I know how to write it in Processing but I can't convert my thinking to the 4 pixel array style of P5. Below if how I am writing the texture with a random function but I would like to change this to noise to create the classic cloud effect.</p>

<p>Thanks a lot, Steven</p>

<pre><code>function setup() {
    var myCanvas = createCanvas(700, 801);
    pixelDensity(1);    
}

function draw(){
    background(255);
    loadPixels();

    for(var y = 0; y &lt; height; y++) {
        for(var x = 0; x &lt; width; x++) {
            var index = (x + y * width)*4;
            pixels[index+0] = random(255);
            pixels[index+1] = 0;
            pixels[index+2] = 180;
            pixels[index+3] = 255;
        }
    }
    updatePixels();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Saving sketch with a transparent background</title>
      <link>https://forum.processing.org/two/discussion/12036/saving-sketch-with-a-transparent-background</link>
      <pubDate>Tue, 11 Aug 2015 18:49:04 +0000</pubDate>
      <dc:creator>dyk2111</dc:creator>
      <guid isPermaLink="false">12036@/two/discussions</guid>
      <description><![CDATA[<p>Hey,</p>

<p>I'm looking for some help with a simple way of saving the frame of a sketch as a png with no background, other than the drawn lines from the script. The sketch essentially reproduces a given image through a series of generated traceur lines, I've included the sketch for reference and it's something I found so I don't fully understand how it works. I'm new to processing so I apologize if this is really basic or if I'm missing something but after looking around, it seems surprisingly more complicated than I initially thought to render with no background. I'm using the latest version of processing 3 by the way.</p>

<pre><code>PGraphics alphaG;

PImage g;
traceur[] traceurs;

void setup(){
size(2500,800);


   alphaG = createGraphics(width,height, JAVA2D);

  g = loadImage("climate.png");

  traceurs = new traceur[0];
  background(255);
  stroke(126,24,175,20);
  for(int a=0;a&lt;120;a++){
    traceurs = (traceur[]) append (traceurs, new traceur());
  }

}

void draw(){
  for(int a=0;a&lt;traceurs.length;a++){
   traceurs[a].dessine(); 
  } 

 image(alphaG, 0,0);
}

class traceur{
    float x,y,an,v;
    float[] rang={-0.05,0.05};
  traceur(){
    x= random(width);y=random(height);
    an=random(TWO_PI);v=random(1.2,1.5);
   rang[0]=random(-0.1,-0.05);
   rang[1]=random(0.05, 0.1);
  }
  void dessine(){
   an+=random(rang[0],rang[1]);
   float newx=x+cos(an)*v;
   float newy=y+sin(an)*v;
   if(newx&lt;0||newx&gt;width||newy&lt;0||newy&gt;height){
     newx=constrain(newx,0,width);
     newy=constrain(newy,0,height);
     an+=random(-PI,PI);
   rang[0]=random(-0.1,-0.05);
   rang[1]=random(0.05, 0.1);
   }
   if(random(100)&lt;1){ 
   rang[0]=random(-0.1,-0.05);
   rang[1]=random(0.05, 0.1);
   }
   float angleChoisi=an;

   float couleur=brightness(g.get(int(newx),int(newy)));
   for(float a=an-PI*0.3;a&lt;an+PI*0.3;a+=PI*0.15){
      int ixe=int(newx+cos(a)*v);
      int igr=int(newy+sin(a)*v);
      float col=brightness(g.get(ixe,igr));
      if(col&lt;couleur){
        couleur=col;
        angleChoisi=a;
      }
   } 
   an=angleChoisi;
   if(random(100)&lt;1){an=an+random(-1,1);}
   line(x,y,newx,newy);
   x=newx;y=newy;

}
  }


 void keyReleased(){
  saveFrame("img#####.png");
}
</code></pre>

<p>I found another code which I tried incorporating that is pretty helpful in rendering with no background, with some pretty clear instructions for beginners, it utilizes pgraphics to render, but since I don't fully understand how the initial code works, I've been having a hard time incorporating the various drawing steps. I've included the original file here for reference.</p>

<pre><code>PGraphics alphaG;

void setup() {
size(1250,800); 
// create an extra pgraphics object for rendering on a transparent background 
 alphaG = createGraphics(width,height, JAVA2D);

// background will be transparent in the png-file 
background(255);
}

void draw() {

  // draw into the pgraphics object
  alphaG.beginDraw();
    alphaG.fill(255,100);
    alphaG.rect(random(width), random(height), 30,30); 
  alphaG.endDraw();

  // draw the second renderer into the window, so we can see something 
  image(alphaG, 0,0);
}

void keyPressed() {
   alphaG.save("alphatest.png"); 
   println("alphatest.png saved.");
}
</code></pre>

<p>Anyways, I hope what I'm asking makes some sense, and I would really appreciate anyone's help on this, thanks.</p>

<p>Best,<br />
David</p>
]]></description>
   </item>
   <item>
      <title>Why does background() not clear the display here?</title>
      <link>https://forum.processing.org/two/discussion/15939/why-does-background-not-clear-the-display-here</link>
      <pubDate>Sat, 09 Apr 2016 19:16:33 +0000</pubDate>
      <dc:creator>colinmorris</dc:creator>
      <guid isPermaLink="false">15939@/two/discussions</guid>
      <description><![CDATA[<p>I've been searching for how to clear the display, and the standard answer seems to be <code>background()</code>. But this hasn't been working in my sketch. I think it's because I was doing manipulation of <code>pixels</code>. Here's a small example that illustrates:</p>

<pre><code>void setup() {
  size (600, 400);
  loadPixels();
  noStroke();
}

void draw() {
}

void circle_pixels(int cx, int cy, float rad, color c) {
  for (int x=0; x&lt;600; x++) {
    for (int y=0; y&lt;400; y++) {
      int idx = y*600+x;
      if (sq(x-cx) + sq(y-cy) &lt;= sq(rad)) {
        pixels[idx] = c;
      }
    }
  }
  updatePixels();
}

void circle(int cx, int cy, float rad, color c) {
  fill(c);
  ellipse(cx, cy, rad, rad);
}

void mouseClicked() {
  background(128);
  color rand_color = color(int(random(255)), int(random(255)), int(random(255)));
  // This doesn't work. Old circles stick around.
  circle_pixels(300, 200, random(300), rand_color);
  // This works. Only shows one circle at once.
  //circle(300, 200, random(300), rand_color);
}
</code></pre>

<p>Can someone help me understand the difference in behaviour here?</p>

<p>If I am doing pixel manipulation, is the recommended way to clear the display just to set <code>pixels[x,y]</code> to grey for each (x,y) coordinate?</p>
]]></description>
   </item>
   <item>
      <title>Accessing pixel data from an Image loaded in the browser</title>
      <link>https://forum.processing.org/two/discussion/15752/accessing-pixel-data-from-an-image-loaded-in-the-browser</link>
      <pubDate>Tue, 29 Mar 2016 16:11:52 +0000</pubDate>
      <dc:creator>craigson</dc:creator>
      <guid isPermaLink="false">15752@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,
I'm trying to access the pixel data of an Image that I'm uploading on the client-side using the drop() method.</p>

<p>Using createImg() creates a p5.dom img object, as opposed to a p5.image, so I attempted to use loadImage(file.data) where file.data is the src as opposed to a string pointing to a local file.  This returns a p5.image object, however the pixels[] array returns as 
<code>pixels: Uint8ClampedArray[4]</code> instead of 'pixels:Array[0]' when the same image is loaded in setup using <code>var img = loadImage("test.jpg");</code>, though my assumption is that there's no real difference between the two as it's just returning information about the buffer being used.</p>

<p>The interesting thing is that console logging the width and height of the image loaded in setup reads 1920 x 1080, whereas the width and height of the image loaded using drop() reads as 1 x 1, despite showing up in the debugger as having the same properties..</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/535/606KK8UVBC62.png" alt="Screen Shot 2016-03-29 at 12.39.41 PM" title="Screen Shot 2016-03-29 at 12.39.41 PM" /></p>

<p>Any thoughts?</p>
]]></description>
   </item>
   <item>
      <title>does offscreen graphics buffer has a pixels array?</title>
      <link>https://forum.processing.org/two/discussion/13857/does-offscreen-graphics-buffer-has-a-pixels-array</link>
      <pubDate>Wed, 09 Dec 2015 14:35:24 +0000</pubDate>
      <dc:creator>luhai</dc:creator>
      <guid isPermaLink="false">13857@/two/discussions</guid>
      <description><![CDATA[<pre><code>function setup() {
  var g = createGraphics(200, 200);
  var img = createImage(200, 200, RGB);
  g.loadPixels();
  println(g.pixels.length);
  img.loadPixels();
  println(img.pixels.length);
}
</code></pre>

<p>print out:</p>

<pre><code>0
160000
</code></pre>
]]></description>
   </item>
   <item>
      <title>Problem with example in reference</title>
      <link>https://forum.processing.org/two/discussion/14635/problem-with-example-in-reference</link>
      <pubDate>Wed, 27 Jan 2016 14:59:59 +0000</pubDate>
      <dc:creator>discoman</dc:creator>
      <guid isPermaLink="false">14635@/two/discussions</guid>
      <description><![CDATA[<p>I am making examples for reference of p5.image to be put in inline documentation (thereby for online reference). I have placed a PR for 3 examples that I was able to make successfully but I am not able to make it work for loadPixel() method of p5Image class.
<a rel="nofollow" href="http://p5js.org/reference/#p5.Image/loadPixels">p5js.org/reference/#p5.Image/loadPixels</a></p>

<p>It is all about porting examples from processing. So I was porting from <a rel="nofollow" href="https://processing.org/reference/PImage_loadPixels_.html">https://processing.org/reference/PImage_loadPixels_.html</a></p>

<p>So my code</p>

<pre><code>            var myImage;
            var halfImage;

            function preload(){
              myImage = loadImage("assets/rockies.jpg");
            }

            function setup(){
              myImage.loadPixels();
              halfImage = width*height/2;
              for(var i=0; i&lt;halfImage; i++){
                myImage.pixels[i+halfImage] = myImage.pixels[i];
              }
              myImage.updatePixels();
            }

            function draw(){
              image(myImage, 0, 0);
            }
</code></pre>

<p>Is not producing expected result.
Then I looked at the loadPixel() of p5 class.<a rel="nofollow" href="http://p5js.org/reference/#p5/loadPixels">p5js.org/reference/#p5/loadPixels</a>.
I guess this too is not producing desired result.
Need someones guidance here. About what is the error in my code for loadPixels() for p5.image above.</p>

<p>PS - To run the code quickly -
1. Open <a href="http://p5js.org/reference/#/p5.Image/set" target="_blank" rel="nofollow">http://p5js.org/reference/#/p5.Image/set</a>
2. Click "edit" in example, delete existing code and paste this.
3. rockies.jpg is present in the assets of p5js-website and is accessible here.</p>

<p>Sorry for big question I tried putting everything I have done for clarity.</p>
]]></description>
   </item>
   <item>
      <title>Trying to split video frames into RGB component images</title>
      <link>https://forum.processing.org/two/discussion/14598/trying-to-split-video-frames-into-rgb-component-images</link>
      <pubDate>Sun, 24 Jan 2016 06:28:29 +0000</pubDate>
      <dc:creator>LDB477</dc:creator>
      <guid isPermaLink="false">14598@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to take a video frame and break out the RGB component information into three separate images.  The problem I seem to be having is that when I load more than one set of pixel information, some strange things start to happen.  You can see in the code below that when I simply reference the information in the original capture it will actually seem to change that information.  I'm not quite getting the loadPixels and updatePixels functions it seems.  Here's a simplified version of my sketch using one of the video examples:</p>

<pre><code>import processing.video.*;

Capture cam;

PImage camR;
PImage camG;
PImage camB;

void setup() {
  size(640, 480);
  colorMode(RGB,255);
  frameRate(1);
  String[] cameras = Capture.list();

  if (cameras == null) {
    println("Failed to retrieve the list of available cameras, will try the default...");
    cam = new Capture(this, 640, 480);
  } if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 0; i &lt; cameras.length; i++) {
      println(cameras[i]);
    }

    // The camera can be initialized directly using an element
    // from the array returned by list():
    cam = new Capture(this, cameras[0]);
    // Or, the settings can be defined based on the text in the list
    //cam = new Capture(this, 640, 480, "Built-in iSight", 30);

    // Start capturing the images from the camera
    cam.start();
  }
}

void draw() {
  if (cam.available() == true) {
    cam.read();
  }
  camR = cam;
  camG = cam;
  camB = cam;
  cam.loadPixels();
  camR.loadPixels();
  camG.loadPixels();
  camB.loadPixels();

  for (int i = 0; i &lt; cam.width*cam.height; i++){

    camR.pixels[i] = color(red(cam.pixels[i]));
    camG.pixels[i] = color(green(cam.pixels[i]));
    camB.pixels[i] = color(blue(cam.pixels[i]));
  }
  cam.updatePixels();
  camR.updatePixels();
  camG.updatePixels();
  camB.updatePixels();
  image(cam,0,0,200,150);
  image(camR,200,0,200,150);
  image(camG,200,150,200,150);
  image(camB,200,300,200,150);

}
</code></pre>

<p>I'm expecting to see the full RGB image when I run image(cam...), but I end up just getting the greyscale RED channel.  The "camG" and "camB" are also displaying the red channel.</p>
]]></description>
   </item>
   <item>
      <title>code giving a voice alert only and only when motion is detected in front of laptop camera</title>
      <link>https://forum.processing.org/two/discussion/14515/code-giving-a-voice-alert-only-and-only-when-motion-is-detected-in-front-of-laptop-camera</link>
      <pubDate>Mon, 18 Jan 2016 10:18:58 +0000</pubDate>
      <dc:creator>Abhi_1122</dc:creator>
      <guid isPermaLink="false">14515@/two/discussions</guid>
      <description><![CDATA[<p>I am a beginner, so I want to know the code by which the laptop's camera detects motion and speaks something like "Alert we have an intruder"
this is the code which I found out in examples....</p>

<p>Code for Background subtraction...</p>

<p>/**
 * Background Subtraction 
 * by Golan Levin. 
 *
 * GSVideo version by Andres Colubri. 
 * 
 * Detect the presence of people and objects in the frame using a simple
 * background-subtraction technique. To initialize the background, press a key.
 */</p>

<p>import codeanticode.gsvideo.*;</p>

<p>int numPixels;
int[] backgroundPixels;
GSCapture video;</p>

<p>void setup() {
  // Change size to 320 x 240 if too slow at 640 x 480
  size(640, 480);</p>

<p>video = new GSCapture(this, width, height);
  video.start();<br />
  numPixels = video.width * video.height;
  // Create array to store the background image
  backgroundPixels = new int[numPixels];
  // Make the pixels[] array available for direct manipulation
  loadPixels();
}</p>

<p>void draw() {
  if (video.available()) {
    video.read(); // Read a new video frame
    video.loadPixels(); // Make the pixels of video available
    // Difference between the current frame and the stored background
    int presenceSum = 0;
    for (int i = 0; i &lt; numPixels; i++) { // For each pixel in the video frame...
      // Fetch the current color in that location, and also the color
      // of the background in that spot
      color currColor = video.pixels[i];
      color bkgdColor = backgroundPixels[i];
      // Extract the red, green, and blue components of the current pixel�s color
      int currR = (currColor &gt;&gt; 16) &amp; 0xFF;
      int currG = (currColor &gt;&gt; 8) &amp; 0xFF;
      int currB = currColor &amp; 0xFF;
      // Extract the red, green, and blue components of the background pixel�s color
      int bkgdR = (bkgdColor &gt;&gt; 16) &amp; 0xFF;
      int bkgdG = (bkgdColor &gt;&gt; 8) &amp; 0xFF;
      int bkgdB = bkgdColor &amp; 0xFF;
      // Compute the difference of the red, green, and blue values
      int diffR = abs(currR - bkgdR);
      int diffG = abs(currG - bkgdG);
      int diffB = abs(currB - bkgdB);
      // Add these differences to the running tally
      presenceSum += diffR + diffG + diffB;
      // Render the difference image to the screen
      pixels[i] = color(diffR, diffG, diffB);
      // The following line does the same thing much faster, but is more technical
      //pixels[i] = 0xFF000000 | (diffR &lt;&lt; 16) | (diffG &lt;&lt; 8) | diffB;
    }
    updatePixels(); // Notify that the pixels[] array has changed
    println(presenceSum); // Print out the total amount of movement
  }
}</p>

<p>// When a key is pressed, capture the background image into the backgroundPixels
// buffer, by copying each of the current frame�s pixels into it.
void keyPressed() {
  video.loadPixels();
  arraycopy(video.pixels, backgroundPixels);
}</p>

<p>Code for frame differencing.....</p>

<p>/**
 * Frame Differencing 
 * by Golan Levin. 
 *
 * GSVideo version by Andres Colubri.<br />
 * 
 * Quantify the amount of movement in the video frame using frame-differencing.
 */</p>

<p>import codeanticode.gsvideo.*;</p>

<p>int numPixels;
int[] previousFrame;
GSCapture video;</p>

<p>void setup() {
  size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480
  // Uses the default video input, see the reference if this causes an error
  video = new GSCapture(this, width, height);
  video.start();<br />
  numPixels = video.width * video.height;
  // Create an array to store the previously captured frame
  previousFrame = new int[numPixels];
  loadPixels();
}</p>

<p>void draw() {
  if (video.available()) {
    // When using video to manipulate the screen, use video.available() and
    // video.read() inside the draw() method so that it's safe to draw to the screen
    video.read(); // Read the new frame from the camera
    video.loadPixels(); // Make its pixels[] array available</p>

<pre><code>int movementSum = 0; // Amount of movement in the frame
for (int i = 0; i &lt; numPixels; i++) { // For each pixel in the video frame...
  color currColor = video.pixels[i];
  color prevColor = previousFrame[i];
  // Extract the red, green, and blue components from current pixel
  int currR = (currColor &gt;&gt; 16) &amp; 0xFF; // Like red(), but faster
  int currG = (currColor &gt;&gt; 8) &amp; 0xFF;
  int currB = currColor &amp; 0xFF;
  // Extract red, green, and blue components from previous pixel
  int prevR = (prevColor &gt;&gt; 16) &amp; 0xFF;
  int prevG = (prevColor &gt;&gt; 8) &amp; 0xFF;
  int prevB = prevColor &amp; 0xFF;
  // Compute the difference of the red, green, and blue values
  int diffR = abs(currR - prevR);
  int diffG = abs(currG - prevG);
  int diffB = abs(currB - prevB);
  // Add these differences to the running tally
  movementSum += diffR + diffG + diffB;
  // Render the difference image to the screen
  pixels[i] = color(diffR, diffG, diffB);
  // The following line is much faster, but more confusing to read
  //pixels[i] = 0xff000000 | (diffR &lt;&lt; 16) | (diffG &lt;&lt; 8) | diffB;
  // Save the current color into the 'previous' buffer
  previousFrame[i] = currColor;
}
// To prevent flicker from frames that are all black (no movement),
// only update the screen if the image has changed.
if (movementSum &gt; 0) {
  updatePixels();
  println(movementSum); // Print the total amount of movement to the console
}
</code></pre>

<p>}
}</p>
]]></description>
   </item>
   <item>
      <title>Overlay one video with transparency over another video</title>
      <link>https://forum.processing.org/two/discussion/14481/overlay-one-video-with-transparency-over-another-video</link>
      <pubDate>Fri, 15 Jan 2016 18:55:53 +0000</pubDate>
      <dc:creator>dito</dc:creator>
      <guid isPermaLink="false">14481@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm having trouble setting up a sketch that overlays a video with transparency over another rolling video.
The video is of a basketball game and the video with transparency has the stats of the game (a bar on the left of the screen).</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/096/7RKKBEG6HZ6V.png" alt="Screen Shot 2016-01-15 at 18.53.14" title="Screen Shot 2016-01-15 at 18.53.14" /></p>

<p>What I would like to do is to have both videos playing at the same time (and firstly that's my problem).
Secondly, I'd like to summon the video with transparency with a mouse click (for example) so that the stats would only be shown upon clicking. And clicking once again the stats would disappear.
I was able to do this with the basketball video and with a png file (image above)...but not with a .mov file.</p>

<p>Is there someone that can help me with this?</p>

<p>Thanks in advance!</p>
]]></description>
   </item>
   <item>
      <title>Moving pixels a row at a time from multiple images to a single new image</title>
      <link>https://forum.processing.org/two/discussion/14450/moving-pixels-a-row-at-a-time-from-multiple-images-to-a-single-new-image</link>
      <pubDate>Thu, 14 Jan 2016 03:57:53 +0000</pubDate>
      <dc:creator>JeffG</dc:creator>
      <guid isPermaLink="false">14450@/two/discussions</guid>
      <description><![CDATA[<p>Not sure if the title describes this properly. I want to take say 100 images and extract a single row of pixels from each image and then reconstitute the images.</p>

<p>load initialPix1-100</p>

<p>get row 1 from each image and make finalpix_one from these rows</p>

<p>get row 2 from each image and make finalpix_two from these rows</p>

<p>get row 3 from each image and make finalpix_three from these rows</p>

<p><code>##########</code></p>

<p><code>void setup(){</code></p>

<p><code> size(400,400);
  img_one = loadImage("initial_one.jpg");
  img_two = loadImage("initial_two.jpg");
  img_three = loadImage("initial_three.jpg");</code></p>

<p><code>finalpix_one.set(0,0, initial_one.get(0,1,initial_one.width,1) );
   finalpix_one.set(0,1, initial_two.get(0,1,initial_two.width,1) );
   finalpix_one.set(0,2, initial_three.get(0,1,initial_three.width,1) );</code></p>

<p><code>finalpix_two.set(0,0, initial_one.get(0,2,initial_one.width,1) );
   finalpix_two.set(0,1, initial_two.get(0,2,initial_two.width,1) );
   finalpix_two.set(0,2, initial_three.get(0,2,initial_three.width,1) );</code></p>

<p><code>finalpix_three.set(0,0, initial_one.get(0,3,initial_one.width,1) );
   finalpix_three.set(0,1, initial_two.get(0,3,initial_two.width,1) );
   finalpix_three.set(0,2, initial_three.get(0,3,initial_three.width,1) );</code></p>

<p>My question is -- does this make sense or would it be easier to do this with pixels[] can anyone see an easy way to pick if this works with taking 2 rows at a time rather than a single row? If I keep spitting out to the final pix will it overwrite it or append like I want-- there has to be a way to do this that I am not seeing.</p>
]]></description>
   </item>
   <item>
      <title>How do I sort pixels in the pixels[] array?</title>
      <link>https://forum.processing.org/two/discussion/14264/how-do-i-sort-pixels-in-the-pixels-array</link>
      <pubDate>Tue, 05 Jan 2016 02:33:32 +0000</pubDate>
      <dc:creator>Hooga</dc:creator>
      <guid isPermaLink="false">14264@/two/discussions</guid>
      <description><![CDATA[<p>I want to get an image and take its pixels and load them into a shape, how do I know which pixels from the pixels[] array?
The fact that some HD images are over millions of pixels is kinda of unsettling. How can I sort the pixels?</p>
]]></description>
   </item>
   <item>
      <title>about movie help!</title>
      <link>https://forum.processing.org/two/discussion/14205/about-movie-help</link>
      <pubDate>Thu, 31 Dec 2015 10:43:08 +0000</pubDate>
      <dc:creator>liong4x</dc:creator>
      <guid isPermaLink="false">14205@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys. 
I have a trouble on my code. 
I want to make a 80x45 pixels mov into 640x360 pixels display.
But, it has a error on row 22.
Help me~~~~</p>

<pre><code>import processing.video.*;
int cell;
int col, row;
Movie m;

void setup() {
  size(640, 360); // 8 times mov
  m = new Movie(this, "m_80_45.mov"); //mov size is 80x45 pixels
  cell = 8;
  col = width/cell;
  row = height/cell;
}

void draw() {
  if (m.available()) {
    m.read();
  }
  m.loadPixels();
  for (int i=0; i&lt;col; i++) {
    for (int j=0; j&lt;row; j++) {
      int loc = i + j*m.width;
      color c = m.pixels[loc]; // this row has error! say: ArrayIndexOutOfBoundsException:0
      fill(c);
      int x = i*cell;
      int y = j*cell;
      rect(x, y, cell, cell);
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to easily replace image with video?</title>
      <link>https://forum.processing.org/two/discussion/14009/how-to-easily-replace-image-with-video</link>
      <pubDate>Wed, 16 Dec 2015 04:43:05 +0000</pubDate>
      <dc:creator>yuyu593</dc:creator>
      <guid isPermaLink="false">14009@/two/discussions</guid>
      <description><![CDATA[<p>Hi</p>

<p>I m a beginner to processing, and i would like to know if it would be possible to change img1 with a new movie"BD,mov". I want that move as the mask1.</p>

<p>Thanks for your help!!</p>

<p>PImage img1;
PImage mask1;
PImage img2;
PImage mask2;
import processing.video.*;
Movie movie;</p>

<p>int threshold = 127;</p>

<p>color black = color(0);
color white = color(255);
int numPixels;
Capture video;</p>

<p>void setup() {
  //size(1920,1280); 
  size(1000, 800);
  strokeWeight(5);</p>

<p>//img1 = loadImage("bd2.jpg");</p>

<p>movie = new Movie(this, "bd.mov");
  movie.loop();
  img2 = loadImage("nagitive.jpg");</p>

<p>// imageMode(CENTER);</p>

<p>// example if it creates an error
  video = new Capture(this, width, height);</p>

<p>// Start capturing the images from the camera
  video.start();</p>

<p>numPixels = video.width * video.height;
  mask1 = createImage(width, height, RGB);
  mask2 = createImage(width, height, ALPHA);
  noCursor();
  smooth();
}</p>

<p>//void mouseDragged() {
//threshold = round(map(mouseX, 0, width, 0, 255));
//}</p>

<p>void movieEvent(Movie m) {
  m.read();
}</p>

<p>void draw() {
  background(0);
  if (video.available()) {
    video.read();
    mask1.copy(video, 0, 0, video.width, video.height, 0, 0, mask1.width, mask1.height);
    numPixels = mask1.width * mask1.height;
    // video.loadPixels();
    //  int threshold = 127; // Set the threshold value
    float pixelBrightness; // Declare variable to store a pixel's color
    // Turn each pixel in the video frame black or white depending on its brightness
    mask1.loadPixels();
    mask2.loadPixels();
    for (int i = 0; i &lt; numPixels; i++) {
      pixelBrightness = brightness(mask1.pixels[i]);
      if (pixelBrightness &gt; threshold) { // If the pixel is brighter than the
        mask1.pixels[i] = white; // threshold value, make it white
        mask2.pixels[i] = black;
      } else { // Otherwise,
        mask1.pixels[i] = black; // make it black
        mask2.pixels[i] = white;
      }
    }
    mask1.updatePixels();
    mask2.updatePixels();
  }</p>

<p>//image(mask1, 0, 0, width/2, height/2);
  //image(mask2, width/2, 0, width/2, height/2);</p>

<p>mask1.resize(movie.width, movie.height);
  mask2.resize(img2.width, img2.height);
  movie.mask(mask1);
  img2.mask(mask2);
  blendMode(ADD);
  //image(img1, 0, height/2, width/2, height/2);
  //image(img2, width/2, height/2, width/2, height/2);
  image(movie, 0, 0, width, height);
  image(img2, 0, 0, width, height);
}</p>
]]></description>
   </item>
   <item>
      <title>Can my messy 3D scanner code be optimized?</title>
      <link>https://forum.processing.org/two/discussion/13832/can-my-messy-3d-scanner-code-be-optimized</link>
      <pubDate>Tue, 08 Dec 2015 08:46:53 +0000</pubDate>
      <dc:creator>roygoh2</dc:creator>
      <guid isPermaLink="false">13832@/two/discussions</guid>
      <description><![CDATA[<p>Hello, we built a 3D scanner and used processing to calculate the cartesian coordinates from the image and output to .asc -file. My code is here:</p>

<p>The code and markings are written in Finnish, but I will try to clarify the code below a bit:</p>

<p>My questions:</p>

<ol>
<li><p>So about NoLoop - function, where should I put it?</p></li>
<li><p>In my function pyorita(), which sends serial data to Arduino, which turns the scanner platter, I must have 1000ms delay, otherwise the program will crash. This makes my program run slow, though. Could this be optimized anyhow? (If I remove the delay, it will just print me "-1" "-1" "-1" in the console with red font (error))s</p></li>
<li><p>Could I anyhow see the latest picture taken by scanner? Now the screen is black until the scan is fully complete. In the end, it shows the LAST (200th) raw picture it took.</p></li>
</ol>

<p>here is my code as it seems impossible for me to properly send it here:
<a href="http://hietanen.xyz/paste/?paste=8" target="_blank" rel="nofollow">http://hietanen.xyz/paste/?paste=8</a></p>
]]></description>
   </item>
   <item>
      <title>Trying to make my countdown faster in Processing Photo Booth</title>
      <link>https://forum.processing.org/two/discussion/13833/trying-to-make-my-countdown-faster-in-processing-photo-booth</link>
      <pubDate>Tue, 08 Dec 2015 10:00:31 +0000</pubDate>
      <dc:creator>iceB</dc:creator>
      <guid isPermaLink="false">13833@/two/discussions</guid>
      <description><![CDATA[<p>Please help. 
I am a total noob, and I need to make the countdown faster in processing + it doesn't capture everything. Some shots are missing/not taken.</p>

<pre><code>import cc.arduino.*;
import org.firmata.*;


import processing.video.*;
import processing.serial.*;
Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

Capture video;


int a = 1024; // width of window
int b = 768;  // height of window
int x = 100;  // x- position text
int y = 700; // y- position text
int capnum = 0;
int countdowntimer = 10;
int globalframecount = 0;
PImage aj;
PImage bj;
PImage cj;
PImage dj;
color black = color(0);
color white = color(255);
int numPixels;

void setup() {
  String portName = Serial.list () [2];
  myPort = new Serial (this, portName, 9600);
  print(Serial.list ());
  frameRate (25);
  size(1024, 768); // Change size to 320 x 240 if too slow at 640 x 480
  strokeWeight(5);

  // This the default video input, see the GettingStartedCapture 
  // example if it creates an error
  video = new Capture(this, width, height, 30);

  // Start capturing the images from the camera
  video.start(); 

  numPixels = video.width * video.height;
  noCursor();
  smooth();
}

void draw() {
  if ( myPort.available() &gt; 0) { 
    val = myPort.read();
  }
  if (val&gt;0) {
    globalframecount = 1;
  }
  println(val);
  if (video.available()) {
    video.read();
    video.loadPixels();
    int threshold = 127;
    float pixelBrightness;
    loadPixels();
    for (int i = 0; i&lt;numPixels; i++) {
      pixelBrightness = brightness(video.pixels[i]);
      if (pixelBrightness &gt; threshold) {
        pixels [i] = white;
      } else { 
        pixels[i] = black;
      }
    }
    updatePixels();
    int testValue = get(mouseX, mouseY);
    float testBrightness = brightness(testValue);
    if (testBrightness &gt; threshold) { // If the test location is brighter than
      fill(black); // the threshold set the fill to black
    } else { // Otherwise,
      fill(white); // set the fill to white
    }
  }



  PFont fontA = loadFont("Serif-48.vlw");
  textFont(fontA);


  noFill();

  switch(val) {

  case 's':
    globalframecount = 1;
    //  background(0);

    break;

  case 't':
    //null
    break;
  default:
    //println("Zulu");   // Prints "Zulu"
    break;
  }

  if (globalframecount == 25) {
    countdowntimer = 9;
  }
  if (globalframecount == 50) {
    countdowntimer = 8;
  }
  if (globalframecount == 75) {
    countdowntimer = 7;
  }
  if (globalframecount == 100) {
    countdowntimer = 6;
  }
  if (globalframecount == 125) {
    countdowntimer = 5;
  }
  if (globalframecount == 150) {
    countdowntimer = 4;
  }
  if (globalframecount == 175) {
    countdowntimer = 3;
  }
  if (globalframecount == 200) {
    countdowntimer = 2;
  }
  if (globalframecount == 225) {
    countdowntimer = 1;
  } 
  //    image (video, 0, 0);

  if ((globalframecount &lt; 250) &amp; (globalframecount &gt; 0)) {
    textFont(fontA, 30);
    fill(0);
    text ("Preview! Get ready for your photo in "+str(countdowntimer), x+2, y);
    text ("Preview! Get ready for your photo in "+str(countdowntimer), x, y+2);
    text ("Preview! Get ready for your photo in "+str(countdowntimer), x-2, y);
    text ("Preview! Get ready for your photo in "+str(countdowntimer), x, y-2);
    textFont(fontA, 30);
    fill(255);
    text ("Preview! Get ready for your photo in "+str(countdowntimer), x, y);
    //text (countdowntimer, width-250, y);
    globalframecount++;
  }

  if ((globalframecount &gt;= 250) &amp; (globalframecount &lt; 500)) {
    // image (video, 0, 0);

    if ((globalframecount &gt; 250) &amp; (globalframecount &lt; 311))
    {
      textFont(fontA, 100);
      fill(0);
      text (str(countdowntimer), width/2+2, height/2);

      text (str(countdowntimer), width/2, height/2+2);

      text (str(countdowntimer), width/2-2, height/2);

      text (str(countdowntimer), width/2, height/2-2);

      fill(255);
      text (str(countdowntimer), width/2, height/2-2);
    }
    if (globalframecount == 250)
    {
      countdowntimer = 3;
    }

    if (globalframecount == 270)
    {
      countdowntimer = 2;
    }

    if (globalframecount == 290)
    {
      countdowntimer = 1;
    }

    if (globalframecount == 312) {
      background(255);
    }
    if (globalframecount == 313) {
      saveFrame(capnum+".jpeg");
      aj = loadImage(capnum+".jpeg");
      capnum++;
    }

    if ((globalframecount &gt; 314) &amp; (globalframecount &lt; 373))
    {
      textFont(fontA, 100);
      fill(0);
      text (str(countdowntimer), width/2+2, height/2);

      text (str(countdowntimer), width/2, height/2+2);

      text (str(countdowntimer), width/2-2, height/2);

      text (str(countdowntimer), width/2, height/2-2);

      fill(255);
      text (str(countdowntimer), width/2, height/2-2);
    }
    if (globalframecount == 314)
    {
      countdowntimer = 3;
    }

    if (globalframecount == 335)
    {
      countdowntimer = 2;
    }

    if (globalframecount == 355)
    {
      countdowntimer = 1;
    }

    if (globalframecount == 374) {
      background(255);
    }

    if (globalframecount == 375) {
      saveFrame(capnum+".jpeg");
      bj = loadImage(capnum+".jpeg");
      capnum++;
    }

    if ((globalframecount &gt; 375) &amp; (globalframecount &lt; 436))
    {
      textFont(fontA, 100);
      fill(0);
      text (str(countdowntimer), width/2+2, height/2);

      text (str(countdowntimer), width/2, height/2+2);

      text (str(countdowntimer), width/2-2, height/2);

      text (str(countdowntimer), width/2, height/2-2);

      fill(255);
      text (str(countdowntimer), width/2, height/2-2);
    }
    if (globalframecount == 376)
    {
      countdowntimer = 3;
    }

    if (globalframecount == 401)
    {
      countdowntimer = 2;
    }

    if (globalframecount == 420)
    {
      countdowntimer = 1;
    }

    if (globalframecount == 438) {
      background(255);
    }

    if (globalframecount == 439) {
      saveFrame(capnum+".jpeg");
      cj = loadImage(capnum+".jpeg");
      capnum++;
    }

    if ((globalframecount &gt; 440) &amp; (globalframecount &lt; 497))
    {
      textFont(fontA, 100);
      fill(0);
      text (str(countdowntimer), width/2+2, height/2);

      text (str(countdowntimer), width/2, height/2+2);

      text (str(countdowntimer), width/2-2, height/2);

      text (str(countdowntimer), width/2, height/2-2);

      fill(255);
      text (str(countdowntimer), width/2, height/2-2);
    }
    if (globalframecount == 440)
    {
      countdowntimer = 3;
    }

    if (globalframecount == 460)
    {
      countdowntimer = 2;
    }

    if (globalframecount == 480)
    {
      countdowntimer = 1;
    }

    if (globalframecount == 497) {
      background(255);
    }    

    if (globalframecount == 498) {
      saveFrame(capnum+".jpeg");
      dj = loadImage(capnum+".jpeg");
      capnum++;
    }

    if (globalframecount == 499) {
      fill(255);
      background(0);
      rect(width/11, height/10, (width-240), (height-100));
      image(aj, width/8, height/8, width/3, height/3);
      image(bj, 4*(width/8), height/8, width/3, height/3);
      image(cj, width/8, 4*(height/8), width/3, height/3);
      image(dj, 4*(width/8), 4*(height/8), width/3, height/3);
      fill(0);
      text ("take a picture it will last longer", x, y);
      saveFrame("multipage"+capnum+".jpeg");
      globalframecount = -1;
    }


    //delay(50);
    globalframecount++;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Super Fast Blur BlobDetection library!!!</title>
      <link>https://forum.processing.org/two/discussion/13743/super-fast-blur-blobdetection-library</link>
      <pubDate>Wed, 02 Dec 2015 07:44:35 +0000</pubDate>
      <dc:creator>FrankOcean</dc:creator>
      <guid isPermaLink="false">13743@/two/discussions</guid>
      <description><![CDATA[<p>today i used the blob detection in p3 and now all of the sudden im getting this msg, why ? also i KNOW ofr a dam fact i downloaded the Video library and now is not there and when i try to download again i get this msg saying 
"Could not move contribution to backup folder" and aside from that SketchMapper says that theres a update but dont let me update when i hit update so it downloaded a library that i cant even use on p3 so WHY let me download something i cant use? i hit remove and it dont remove the library, im just about done with p3 for real this is garbage way toooooo many bad things for a so call upgrade if you ask me i mean you dont even have the OpenCV library com'on now !</p>

<pre><code>ERROR:

video does not run on this architecture: 64
processing.app.SketchException: video is only compatible with the  32-bit download of Processing.
    at processing.mode.java.runner.Runner.&lt;init&gt;(Runner.java:107)
video does not run on this architecture: 64 at processing.mode.java.JavaMode.handleLaunch(JavaMode.java:155)

    at processing.mode.java.JavaEditor$36.run(JavaEditor.java:1099)
    at java.lang.Thread.run(Thread.java:745)
processing.app.SketchException: video is only compatible with the  32-bit download of Processing.
    at processing.mode.java.runner.Runner.&lt;init&gt;(Runner.java:107)
    at processing.mode.java.JavaMode.handleLaunch(JavaMode.java:155)
    at processing.mode.java.JavaEditor$36.run(JavaEditor.java:1099)
    at java.lang.Thread.run(Thread.java:745)

// - Super Fast Blur v1.1 by Mario Klingemann &lt;<a href="http://incubator.quasimondo.com&gt" target="_blank" rel="nofollow">http://incubator.quasimondo.com&gt</a>;
// - BlobDetection library

import processing.video.*;
import blobDetection.*;

Capture cam;
BlobDetection theBlobDetection;
PImage img;
boolean newFrame=false;

// ==================================================
// setup()
// ==================================================
void setup()
{
    // Size of applet
    size(640, 480);
    // Capture
    cam = new Capture(this,width,height, "USB2.0 Camera");
        // Comment the following line if you use Processing 1.5
        cam.start();

    // BlobDetection
    // img which will be sent to detection (a smaller copy of the cam frame);
    img = new PImage(80,60); 
    theBlobDetection = new BlobDetection(img.width, img.height);
    theBlobDetection.setPosDiscrimination(true);
    theBlobDetection.setThreshold(0.2f); // will detect bright areas whose luminosity &gt; 0.2f;
}

// ==================================================
// captureEvent()
// ==================================================
void captureEvent(Capture cam)
{
    cam.read();
    newFrame = true;
}

// ==================================================
// draw()
// ==================================================
void draw()
{
    if (newFrame)
    {
        newFrame=false;
        image(cam,0,0,width,height);
        img.copy(cam, 0, 0, cam.width, cam.height, 
                0, 0, img.width, img.height);
        fastblur(img, 2);
        theBlobDetection.computeBlobs(img.pixels);
        drawBlobsAndEdges(true,true);
    }
}

// ==================================================
// drawBlobsAndEdges()
// ==================================================
void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges)
{
    noFill();
    Blob b;
    EdgeVertex eA,eB;
    for (int n=0 ; n&lt;theBlobDetection.getBlobNb() ; n++)
    {
        b=theBlobDetection.getBlob(n);
        if (b!=null)
        {
            // Edges
            if (drawEdges)
            {
                strokeWeight(3);
                stroke(0,255,0);
                for (int m=0;m&lt;b.getEdgeNb();m++)
                {
                    eA = b.getEdgeVertexA(m);
                    eB = b.getEdgeVertexB(m);
                    if (eA !=null &amp;&amp; eB !=null)
                        line(
                            eA.x*width, eA.y*height, 
                            eB.x*width, eB.y*height
                            );
                }
            }

            // Blobs
            if (drawBlobs)
            {
                strokeWeight(1);
                stroke(255,0,0);
                rect(
                    b.xMin*width,b.yMin*height,
                    b.w*width,b.h*height
                    );
            }

        }

      }
}

// ==================================================
// Super Fast Blur v1.1
// by Mario Klingemann 
// &lt;<a href="http://incubator.quasimondo.com&gt" target="_blank" rel="nofollow">http://incubator.quasimondo.com&gt</a>;
// ==================================================
void fastblur(PImage img,int radius)
{
 if (radius&lt;1){
    return;
  }
  int w=img.width;
  int h=img.height;
  int wm=w-1;
  int hm=h-1;
  int wh=w*h;
  int div=radius+radius+1;
  int r[]=new int[wh];
  int g[]=new int[wh];
  int b[]=new int[wh];
  int rsum,gsum,bsum,x,y,i,p,p1,p2,yp,yi,yw;
  int vmin[] = new int[max(w,h)];
  int vmax[] = new int[max(w,h)];
  int[] pix=img.pixels;
  int dv[]=new int[256*div];
  for (i=0;i&lt;256*div;i++){
    dv[i]=(i/div);
  }

  yw=yi=0;

  for (y=0;y&lt;h;y++){
    rsum=gsum=bsum=0;
    for(i=-radius;i&lt;=radius;i++){
      p=pix[yi+min(wm,max(i,0))];
      rsum+=(p &amp; 0xff0000)&gt;&gt;16;
      gsum+=(p &amp; 0x00ff00)&gt;&gt;8;
      bsum+= p &amp; 0x0000ff;
    }
    for (x=0;x&lt;w;x++){

      r[yi]=dv[rsum];
      g[yi]=dv[gsum];
      b[yi]=dv[bsum];

      if(y==0){
        vmin[x]=min(x+radius+1,wm);
        vmax[x]=max(x-radius,0);
      }
      p1=pix[yw+vmin[x]];
      p2=pix[yw+vmax[x]];

      rsum+=((p1 &amp; 0xff0000)-(p2 &amp; 0xff0000))&gt;&gt;16;
      gsum+=((p1 &amp; 0x00ff00)-(p2 &amp; 0x00ff00))&gt;&gt;8;
      bsum+= (p1 &amp; 0x0000ff)-(p2 &amp; 0x0000ff);
      yi++;
    }
    yw+=w;
  }

  for (x=0;x&lt;w;x++){
    rsum=gsum=bsum=0;
    yp=-radius*w;
    for(i=-radius;i&lt;=radius;i++){
      yi=max(0,yp)+x;
      rsum+=r[yi];
      gsum+=g[yi];
      bsum+=b[yi];
      yp+=w;
    }
    yi=x;
    for (y=0;y&lt;h;y++){
      pix[yi]=0xff000000 | (dv[rsum]&lt;&lt;16) | (dv[gsum]&lt;&lt;8) | dv[bsum];
      if(x==0){
        vmin[y]=min(y+radius+1,hm)*w;
        vmax[y]=max(y-radius,0)*w;
      }
      p1=x+vmin[y];
      p2=x+vmax[y];

      rsum+=r[p1]-r[p2];
      gsum+=g[p1]-g[p2];
      bsum+=b[p1]-b[p2];

      yi+=w;
    }
  }

}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>